package tyk.preparedstatement;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/***
 *@title run
 *@description <TODO description class purpose>
 *@author Tang'ya'kang
 *@VERSION 1.0.0
 *@CREATE 2023/5/4 21:10
 **/
public class run {
    //Todo:事务提交及回滚
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection= DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/javaweb?rewriteBatchedStatements=true","root","123456");
        add a=new add(connection);
        sub s=new sub(connection);
        String account1="ergouzi",account2="lvdandan";
        int money = 500;
        try{
            connection.setAutoCommit(false);
            a.adds(account1,money);
            System.out.println("加钱成功");
            s.subs(account2,money);
            System.out.println("减钱成功");
            connection.commit();
        } catch (Exception e) {
            e.printStackTrace();
            connection.rollback();
        }
        finally {
            connection.setAutoCommit(true);
            connection.close();
        }
    }
}
